package Servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CalculatePollResult extends HttpServlet{
	QueryExcecution.CalculatePollResult cpr=new QueryExcecution.CalculatePollResult();
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws IOException, ServletException {
		try{
			doPost(req, res);
		}
		catch(Exception e){
			
		}
	}///do get///////
	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws IOException, ServletException {
		double result[] =new double[3];	
		HttpSession ses=req.getSession();

		System.out.println("hello calculate poll result  called !!");
			int choice=Integer.parseInt(req.getParameter("choice"));
			//System.out.println("your choice is ====="+choice);
			result=cpr.calculateResult(choice);
			//System.out.println("yes percentage is ==="+result[0]+"No percentage is===="+result[1]+"Cant Say Percentage is ===="+result[2]);
			String SYes=String.valueOf(result[0]);
			String SNo=String.valueOf(result[1]);
			String SCantSay=String.valueOf(result[2]);
			System.out.println("the string is ====="+SYes);
			ses.setAttribute("SYes", SYes);
			ses.setAttribute("SNo", SNo);
			ses.setAttribute("SCantSay", SCantSay);
			RequestDispatcher requestDispatcher = req
					.getRequestDispatcher("./index.jsp");
			requestDispatcher.forward(req, res);
	}
}
